'use strict';
import React,{Component} from 'react';
import Util from '../common/util';
import styles from '../style/styles';
import * as URLconstant from '../constant/URLconstant'
import PinIndex from '../marketing/pintuan/index';//拼团详情
import PinList from '../marketing/pintuan/list';//更多拼团列表
import {
    View,
    Text,
    Image,
    TouchableOpacity,
    TextInput,
    ScrollView
} from 'react-native';
export default class homeGroup extends Component{
    // 构造
      constructor(props) {
        super(props);
        // 初始状态
        this.state = {
            pin_ing:[]
        };
        this.getListSuc=this.getListSuc.bind(this)
          this.errorCallback=this.errorCallback.bind(this)
      }

    componentDidMount() {
        this.getPinList()
    }
    getPinList(){
          let url = URLconstant.GET_PIN_LIST
        let datakey=[]
        datakey['user_id']=1
        Util.get(url,datakey,this.getListSuc,this.errorCallback)
    }
    getListSuc(datas){
        if(datas.status==0){
            this.setState({
                pin_ing:datas.data.pin_ing
            })
        }
    }
    errorCallback(err){

    }

    toPinIndex(id,goods_id){
          this.props.navigator.push({
              component:PinIndex,
              passProps:{
                  pin_id:id,
                  goods_id:goods_id
              }
          })
    }

    toPinList(){
          this.props.navigator.push({
              component:PinList
          })
    }


      render(){
          let pin_ing = this.state.pin_ing
          return(
              <View>
                  {
                      pin_ing.length==0?
                          null:
                          <View style={{paddingTop:10,backgroundColor:"#fff"}}>
                              <View style={styles.home_group_header}>
                                  <View style={{flexDirection:'row',alignItems:"center"}}>
                                      <Text style={{fontSize:18,color:"#000",marginLeft:10,}}>火热拼团</Text>
                                      <Text style={{fontSize:12,color:"#000"}}>/GROUP PURCHASING NG</Text>
                                  </View>
                                  <TouchableOpacity onPress={()=>this.toPinList()}>
                                      <Text style={{fontSize:12,color:"#969696"}}>更多></Text>
                                  </TouchableOpacity>
                              </View>
                              <ScrollView style={{width:Util.size.width,paddingLeft:5,paddingRight:5,paddingBottom:10}} horizontal={true}>
                                  {
                                      pin_ing.map((item,index)=>{
                                          return(
                                              <TouchableOpacity onPress={()=>this.toPinIndex(item.id,item.goods_id)} style={styles.home_group_item} key={index}>
                                                  <View style={{width:150, height:150}}>
                                                      <Image
                                                          source={{uri:item.default_image}}
                                                          style={{width:150, height:150}}
                                                          resizeMode={'cover'}
                                                      />
                                                  </View>
                                                  <View style={styles.group_goods_txt}>
                                                      <Text numberOfLines={1} style={{fontSize:12,color:"#666"}}>{item.goods_name}</Text>
                                                      <View style={styles.price_view}>
                                                          <Text style={{fontSize:16,color:"#9e0a16",marginRight:10}}>¥{item.act_price}</Text>
                                                          <Text style={{fontSize:12,color:"#969696",textDecorationLine:'line-through'}}>¥{item.market_price}</Text>
                                                      </View>
                                                  </View>
                                                  <View style={{width:150,height:25,alignItems:'center',justifyContent:"center",backgroundColor:"#9e0a16"}}>
                                                      <Text style={{fontSize:12,color:"#fff"}}>去拼团</Text>
                                                  </View>
                                              </TouchableOpacity>
                                          )
                                      })
                                  }
                              </ScrollView>
                          </View>
                  }
              </View>
          )
      }
}